package com.frcdi.qms.equipment.service.impl;

import com.frcdi.qms.common.constant.UserConstants;
import com.frcdi.qms.common.utils.StringUtils;
import com.frcdi.qms.equipment.domain.EquipmentCommunication;
import com.frcdi.qms.equipment.mapper.EquipmentCommunicationMapper;
import com.frcdi.qms.equipment.service.IEquipmentCommunicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备通讯配置Service业务层处理
 *
 * @author cell
 * @date 2023-12-26
 */
@Service
public class EquipmentCommunicationServiceImpl implements IEquipmentCommunicationService
{
    @Autowired
    private EquipmentCommunicationMapper equipmentCommunicationMapper;

    /**
     * 查询设备通讯配置
     *
     * @param id 设备通讯配置主键
     * @return 设备通讯配置
     */
    @Override
    public EquipmentCommunication selectEquipmentCommunicationById(Long id)
    {
        return equipmentCommunicationMapper.selectEquipmentCommunicationById(id);
    }

    /**
     * 查询设备通讯配置列表
     *
     * @param equipmentCommunication 设备通讯配置
     * @return 设备通讯配置
     */
    @Override
    public List<EquipmentCommunication> selectEquipmentCommunicationList(EquipmentCommunication equipmentCommunication)
    {
        return equipmentCommunicationMapper.selectEquipmentCommunicationList(equipmentCommunication);
    }

    /**
     * 新增设备通讯配置
     *
     * @param equipmentCommunication 设备通讯配置
     * @return 结果
     */
    @Override
    public int insertEquipmentCommunication(EquipmentCommunication equipmentCommunication)
    {
        return equipmentCommunicationMapper.insertEquipmentCommunication(equipmentCommunication);
    }

    /**
     * 修改设备通讯配置
     *
     * @param equipmentCommunication 设备通讯配置
     * @return 结果
     */
    @Override
    public int updateEquipmentCommunication(EquipmentCommunication equipmentCommunication)
    {
        return equipmentCommunicationMapper.updateEquipmentCommunication(equipmentCommunication);
    }

    /**
     * 批量删除设备通讯配置
     *
     * @param ids 需要删除的设备通讯配置主键
     * @return 结果
     */
    @Override
    public int deleteEquipmentCommunicationByIds(Long[] ids)
    {
        return equipmentCommunicationMapper.deleteEquipmentCommunicationByIds(ids);
    }

    /**
     * 删除设备通讯配置信息
     *
     * @param id 设备通讯配置主键
     * @return 结果
     */
    @Override
    public int deleteEquipmentCommunicationById(Long id)
    {
        return equipmentCommunicationMapper.deleteEquipmentCommunicationById(id);
    }

    @Override
    public boolean checkequipmentUnique(EquipmentCommunication equipmentCommunication) {
        Long id = StringUtils.isNull(equipmentCommunication.getId()) ? -1L : equipmentCommunication.getId();
        EquipmentCommunication info = equipmentCommunicationMapper.checkequipmentUnique(equipmentCommunication.getEquipment());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue()) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
